package com.aliyun.heiyu.powermaster.server.dao.impl;

import com.aliyun.heiyu.common.util.JdbcUtil;
import com.aliyun.heiyu.powermaster.server.dao.CapFminDao;
import com.aliyun.heiyu.powermaster.server.dao.entity.CapFminEntity;

import java.util.List;

public class CapFminImpl implements CapFminDao {
    @Override
    public boolean insert(CapFminEntity entity) {
        String sql = "insert into capping_fmin(device_id,fmin,date,f_uncapping) values (?,?,?,?)";
        Object[] kk = new Object[4];
        kk[0]=entity.getDevice_id();
        kk[1]=entity.getFmin();
        kk[2] = entity.getDate();
        kk[3] = entity.getF_uncapping();
        return JdbcUtil.update(sql, kk);
    }

    @Override
    public CapFminEntity findOne(String deviceId) {
        String sql = "select * from capping_fmin where 1 = ? and device_id=? order by id desc limit 0,1";
        Object[] kk = new Object[2];
        kk[0]=1;
        kk[1]=deviceId;
        return JdbcUtil.queryForBean(sql,kk,CapFminEntity.class);
    }

    @Override
    public List<CapFminEntity> findByTime(String deviceId, String startTime, String endTime) {
        String sql = "select id,fmin,f_uncapping,date from capping_fmin where device_id=? and date >= ? and date <= ?";
        String[] kk = new String[3];
        kk[0] = deviceId;
        kk[1] = startTime;
        kk[2] = endTime;
        List<CapFminEntity> result = JdbcUtil.queryForList(sql,kk,CapFminEntity.class);
        return result;
    }

}
